package com.joysuch.wwyt.patrol.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.joysuch.wwyt.core.bean.vo.KeyValueVO;
import com.joysuch.wwyt.patrol.entity.PatrolCheckPlan;
import com.joysuch.wwyt.patrol.entity.bean.PatrolCheckSearchBean;
import com.joysuch.wwyt.patrol.entity.bean.PatrolDailySearchBean;
import com.joysuch.wwyt.patrol.entity.bean.StatPlanTitleSearchBean;
import com.joysuch.wwyt.patrol.entity.dto.CheckPlanPageDto;
import com.joysuch.wwyt.patrol.entity.dto.PatrolCheckReportDto;
import com.joysuch.wwyt.patrol.entity.dto.PatrolDailyReportDto;
import com.joysuch.wwyt.patrol.entity.dto.StatPlanTitleDto;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author zr
 * @since 2022-02-28
 */
@Repository
public interface PatrolCheckPlanMapper extends BaseMapper<PatrolCheckPlan> {

    /**
     * 检查计划的分页(计划的更改则将上一个计划禁用,同时新增一个unique_id一样,版本号planVersion加一的计划)
     * 查找时则寻找同一个unique_id中最高版本号的计划
     *
     * @param pageDtoPage 分页
     * @param nameOrCode  名称或者编号
     * @return
     */
    Page<CheckPlanPageDto> selectListByPage(Page pageDtoPage, Long tenentId, String orgCode, String nameOrCode, Set<Long> authDepartIds, Long responsibleDeptId);
    Page<CheckPlanPageDto> selectListByPage(Page pageDtoPage,Long tenentId,String orgCode, String nameOrCode,Set<Long> authDepartIds,Long responsibleDeptId,String statusName);


    PatrolCheckPlan getPlanDetailById(Long tenentId, String orgCode, Long planId);

    /**
     * 将该计划禁用
     *
     * @param planId
     */
    void disabledByPlanId(Long planId);

    /**
     * 根据id关闭检查计划
     *
     * @param planId
     * @param flag   0：将计划关闭  1：将计划开启
     * @return
     */
    void closeOrOpenPlan(Long planId, String flag);

    void deletePlanById(Long planId);

    /**
     * 根据名称判断是否有重名
     *
     * @param checkPlanName
     * @return
     */
    Long judgeForName(String checkPlanName, Long tenentId, String orgCode);

    /**
     * 判断除了自己外有没有重复的名称
     *
     * @param id
     * @param checkPlanName
     * @return
     */
    Long judgeForNameExcludeSelf(Long id, String checkPlanName, Long tenentId, String orgCode);

    Page<PatrolDailyReportDto> statisticsListByUser(Page<PatrolDailyReportDto> page, PatrolDailySearchBean searchBean, Long tenantId, String orgCode);

    List<PatrolDailyReportDto> statisticsListByUser(PatrolDailySearchBean searchBean, Long tenantId, String orgCode);


    PatrolDailyReportDto queryStatisticsByUser(PatrolDailySearchBean searchBean, Long tenantId, String orgCode);

    Page<PatrolDailyReportDto> statisticsListByPlan(Page<PatrolDailyReportDto> page, PatrolDailySearchBean searchBean, Long tenantId, String orgCode);

    List<PatrolDailyReportDto> statisticsListByPlan(PatrolDailySearchBean searchBean, Long tenantId, String orgCode);

    PatrolDailyReportDto queryStatisticsByPlan(PatrolDailySearchBean searchBean, Long tenantId, String orgCode);

    Page<PatrolCheckReportDto> checkReportPlanStat(Page<PatrolCheckReportDto> page, PatrolCheckSearchBean searchBean, Long tenantId, String orgCode);

    String selectNameByTaskId(Long taskId);

    List<PatrolCheckPlan> getLastVersionPlanList(Long tenantId, String orgCode, String planName);

    List<String> selectAllName(@Param("tenentId") Long tenentId, @Param("orgCode") String orgCode);

    List<String> selectAllByName(@Param("tenentId") Long tenentId, @Param("orgCode") String orgCode, @Param("planName") String planName);

    Page<StatPlanTitleDto> pagePlanTitle(Page<StatPlanTitleDto> page, @Param("searchBean") StatPlanTitleSearchBean searchBean);

    List<KeyValueVO<String, String>> listAllNameAndIdGroup(@Param("tenantId") Long tenantId, @Param("orgCode") String orgCode, @Param("planName") String planName);
}
